<template>
	<view class="content" :style="app_bg">
		<view class="topTitle" style="left: -30rpx;" :style="'top:'+zhuangtai+'px'">
			<view class="" style="font-size: 32rpx;">
				个人中心
			</view>
		</view>
		<view class="user" :style="user_margin_top">
			<view class="userinfo">
				<image class="avatar" :src="avatar" mode=""></image>
				<view class="user-lv-name">
					<view class="font30 margin-bottom" :style="font_1st">{{nickname}}</view>
					<view class="font28"style="display: flex;align-items: center;" :style="font_1st">
						<image style="width: 30upx;height: 30upx;margin-right: 10upx;" :src="level_image" mode=""></image>
						<text>lv.{{level}}</text>
					</view>
				</view>
			</view>
			<view class="exchangebtn" @click="gotoExchageShop">
				<image class="bgimgpublic index-0"  :src="diyImg.btn_xs_warm" mode=""></image>
				<text class="font30 index-1" :style="font_1st">兑换商店</text>
			</view>
		</view>
		<view class="userOther" :style="app_theme">
			<view class="item" @click="goToDiamondsList">
				<image class="item-image" :src="appConfig.money_image" mode=""></image>
				<text class="font28 text1" :style="font_1st">{{appConfig.money_name}}</text>
				<text class="font30 fontw500" :style="font_3rd">{{mymoney}}</text>
			</view>
			<view class="item" @click="goToCardList">
				<image class="item-image" :src="diyImg.user_card_icon" mode=""></image>
				<text class="font28 text1" :style="font_1st">卡片</text>
				<text class="font30 fontw500" :style="font_3rd">{{card_total}}</text>
			</view>
			<view class="item" @click="goTogameicon">
				<image class="item-image" :src="appConfig.game_coin_image" mode=""></image>
				<text class="font28 text1" :style="font_1st">{{appConfig.game_coin_name}}</text>
				<text class="font30 fontw500" :style="font_3rd">{{game_coin}}</text>
			</view>
			<view class="item" @click="gotoIntegrall">
				<image class="item-image" :src="appConfig.gold_coin_image" mode=""></image>
				<text class="font28 text1" :style="font_1st">{{appConfig.gold_coin_name}}</text>
				<text class="font30 fontw500" :style="font_3rd">{{gold_coin}}</text>
			</view>
		</view>
		<swiper class="swiperindex" :autoplay="true" :indicator-dots="true" :circular="true">
			<block v-for="(item, index) in bannerList" :key="index">
				<swiper-item :autoplay="true" :interval="3000" :circular="true">
					<image :style="'height:100%;width:100%;'":src="item.image" mode="" @click="goToOtherApp(item)"></image>
				</swiper-item>
			</block>
		</swiper>
		<view class="itemindex" :style="app_theme">
			<view class="item" @click="goToexchage" :style="app_border_bottom">
				<view class="itemleft">
					<image class="image1" :src="diyImg.user_exchange_icon" mode=""></image>
					<text class="font30" :style="font_1st">兑换记录</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</view>
			<view class="item" @click="goToWithdrawal" :style="app_border_bottom">
				<view class="itemleft">
					<image class="image1" :src="diyImg.user_cash_out_icon" mode=""></image>
					<text class="font30" :style="font_1st">提现</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</view>
			<view class="item" @click="goToProblem" :style="app_border_bottom">
				<view class="itemleft">
					<image class="image2" :src="diyImg.user_qa_icon" mode=""></image>
					<text class="font30" :style="font_1st">常见问题</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</view>
			<view class="item" @click="goToDistribution" :style="'border-bottom:2rpx solid '+publicTextColor.app_border_color+';'">
				<view class="itemleft">
					<image class="image3" src="../../static/distribution_icon.png" mode=""></image>
					<text class="font30" :style="font_1st">分销中心</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</view>
			<view class="item" @click="goToOpinion" :style="'border-bottom:2rpx solid '+publicTextColor.app_border_color+';'">
				<view class="itemleft">
					<image class="image3" :src="diyImg.user_feedback_icon" mode=""></image>
					<text class="font30" :style="font_1st">意见反馈</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</view>
			<button class="item" open-type="contact" :show-message-card="true" send-message-title="测试会话" :send-message-img="gotoimage" send-message-path="/pages/index/index?id=1" type="default">
				<view class="itemleft">
					<image class="image4" :src="diyImg.user_contact_us_icon" mode=""></image>
					<text class="font30" :style="font_1st">联系我们</text>
				</view>
				<image class="itemnext" :src="diyImg.btn_next" mode=""></image>
			</button>
		</view>
		<view class="footTabList" :style="'background:'+publicTextColor.app_theme_color+';'+(is_iphone?'padding-bottom:40rpx;':'padding-bottom:10rpx;')">
			<view class="listitem" @click="goToTab(item.url,item.url_name)" v-for="(item, index) in menu" :key="index">
				<image :src="item.name=='我的'?item.icon_selected : item.icon" mode=""></image>
				<view  :style="item.name=='我的'? 'color:'+item.font_color_selected:'color:'+item.font_color">{{item.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				publicTextColor:'',
				zhuangtai:0,
				is_iphone:false,
				menu:[],
				nickname:"",
				avatar:'',
				mymoney:0,
				gold_coin:0,
				game_coin:0,
				exp:0,
				card_total:0,
				diyImg:'',
				appConfig:'',
				bannerList:[],
				level:0,
				level_image:'',
				gotopath:'',
				gotoimage:'../../static/goods-item.png',
				distribution_status:0
			};
		},
		onShow() {
			this.getMyIndexData()
			this.menu = uni.getStorageSync("menu")
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
						that.is_iphone = true
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		onLoad() {
			this.setcolorConfig()
		},
		onShareAppMessage() { // 分享 buttom share
			return {
				title: '合成王者',
				path: '/pages/index/index?parent_id='+uni.getStorageSync('member_id')
			}
		},
		computed:{
			user_margin_top(){
				return `margin-top:${(this.zhuangtai+52)}px;background:${this.publicTextColor.app_theme_color};'`
			},
			app_border_top(){
				return `border-top:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border_bottom(){
				return `border-bottom:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_theme(){
				return `background:${this.publicTextColor.app_theme_color};`
			},
			app_bg(){
				return `background:${this.publicTextColor.app_bg_color};`
			},
			font_3rd(){
				return `color:${this.publicTextColor.font_3rd_color};`
			},
			font_2nd(){
				return `color:${this.publicTextColor.font_2nd_color};`
			},
			font_1st(){
				return `color:${this.publicTextColor.font_1st_color};`
			}
		},
		methods:{
			goToDistribution(){
				if(this.distribution_status == 0 || this.distribution_status == 1){
					uni.navigateTo({
						url:'../../synthesis/other/distributionIndex'
					})
				}else if(this.distribution_status == 2){
					uni.navigateTo({
						url:'../../synthesis/other/distributionMy'
					})
				}
			},
			getMyIndexData(){
				let _self = this
				uni.request({
					url: util.getUrl("member/index"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.nickname = res.data.data.nickname
							_self.avatar = res.data.data.avatar
							_self.mymoney = res.data.data.money
							_self.gold_coin = res.data.data.gold_coin
							_self.game_coin = res.data.data.game_coin
							_self.exp = res.data.data.exp
							_self.card_total = res.data.data.card_total
							_self.bannerList = res.data.data.banner
							_self.level = res.data.data.level
							_self.level_image = res.data.data.level_image
							_self.distribution_status = res.data.data.distribution_status
						}else{
							if(res.data.code == 500){
								uni.navigateTo({
									url:'../login/login'
								})
							}
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			},
			goToOtherApp(item){
				if(item.type == 2){
					uni.navigateToMiniProgram({
						appId: item.other_appid,
						path: item.other_url,
						success(res) {
							console.log(res,"打开成功")
						},
						fail: (e) => {
							console.log(e,"打开失败")
							uni.showToast({
								title:'参数不正确',
								icon:'none'
							})
						}
					})
				}
			},
			goToWithdrawal(){
				uni.navigateTo({
					url:'../../synthesis/other/withdrawalIndex'
				})
			},
			goTogameicon(){
				uni.navigateTo({
					url:'../../synthesis/other/gamecoin'
				})
			},
			gotoExchageShop(){
				uni.navigateTo({
					url:"../../synthesis/other/exchangeShop"
				})
			},
			goToCardList(){
				uni.navigateTo({
					url:'../../synthesis/other/myCardList'
				})
			},
			goToOpinion(){
				uni.navigateTo({
					url:"../../synthesis/other/postOpinion"
				})
			},
			goToProblem(){
				uni.navigateTo({
					url:"../../synthesis/other/problemList"
				})
			},
			goToexchage(){
				uni.navigateTo({
					url:"../../synthesis/other/exchangeList"
				})
			},
			gotoIntegrall(){
				uni.navigateTo({
					url:"../../synthesis/other/integralList"
				})
			},
			goToDiamondsList(){
				uni.navigateTo({
					url:'../../synthesis/other/diamondsList'
				})
			},
			goToTab(url,url_name){
				console.log(url)
				if(url_name == "首页"){
					uni.reLaunch({
						url:'../../synthesis/other/index'
					})
				}else if(url_name == "任务"){
					uni.reLaunch({
						url:'../../pages/task/index'
					})
				}else if(url_name == '我的'){
					
				}
			},
			setcolorConfig(){
				this.publicTextColor = uni.getStorageSync("diyColor")
				this.diyImg = uni.getStorageSync("diyImg")
				this.appConfig = uni.getStorageSync("appconfig")
			},
		}
	}
</script>

<style lang="scss">
	.itemindex{
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		padding: 0 26rpx 0 32rpx;
		width: 690rpx;
		border-radius: 20rpx;
		
		.item{
			display: flex;
			align-items: center;
			width: 100%;
			justify-content: space-between;
			padding: 28rpx 0 31rpx 0;
			box-sizing: border-box;
			background: rgba(0,0,0,0);
			&::after{
				background:none;
				border: none;
				padding: 0;
				margin: 0;
			}
			.itemleft{
				display: flex;
				align-items: center;
				line-height: 1;
				.image1{
					height: 36rpx;
					width: 46rpx;
					margin-right: 16rpx;
				}
				.image2{
					height: 47rpx;
					width: 47rpx;
					margin-right: 16rpx;
				}
				.image3{
					height: 37rpx;
					width: 47rpx;
					margin-right: 16rpx;
				}
				.image4{
					height: 43rpx;
					width: 49rpx;
					margin-right: 16rpx;
				}
				
			}
			.itemnext{
				height: 31rpx;
				width: 20rpx;
			}
		}
	}
	.swiperindex{
		width: 690rpx;
		height: 205rpx;
		border-radius: 12rpx;
		margin-bottom: 30rpx;
	}
	.userOther{
		width: 690rpx;
		padding: 25rpx 0 28rpx 0;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-around;
		border-radius: 20rpx;
		margin-bottom: 30rpx;
		.item{
			display: flex;
			flex-direction: column;
			align-items: center;
			.item-image{
				width: 91rpx;
				height: 92rpx;
				margin-bottom: 19rpx;
			}
			.text1{
				margin-bottom: 21rpx;
			}
		}
	}
	.user{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 690rpx;
		box-sizing: border-box;
		padding: 32rpx 26rpx 31rpx 31rpx;
		border-radius: 20rpx;
		margin-bottom: 29rpx;
		.userinfo{
			display: flex;
			align-items: center;
			.user-lv-name{
				display: flex;
				flex-direction: column;
				.margin-bottom{
					margin-bottom:15rpx;
				}
			}
			.avatar{
				width: 90rpx;
				height: 90rpx;
				margin-right: 24rpx;
				border-radius: 12rpx;
			}
		}
		
		.exchangebtn{
			width: 159rpx;
			height: 56rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
		}
	}
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 150rpx;
		box-sizing: border-box;
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		padding-left: 30rpx;
		justify-content: center;
		position: absolute;
		z-index: 10;
		width: 100%;
	}
	.footTabList{
		display: flex;
		align-items: center;
		justify-content: space-around;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		font-size: 24rpx;
		z-index: 999;
		padding-top: 12rpx;
		.listitem{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100rpx;
			image{
				width: 42rpx;
				height: 42rpx;
				margin-bottom: 15rpx;
			}
		}
	}
</style>
